
from djapeclienttest import *

class TestGeo(TestCase):
    """Test geospatial searching stuff.

    """
    def pre_test(self):
        self.c = djape.client.Client(self.address)

    def post_test(self):
        try:
            self.c.deldb(self.testdb)
        except self.c.SearchClientError:
            pass

    def test_latlong_parse(self):
        # Check a valid coordinate
        ll = self.c.parse_latlong('52.4 -2.35')
        self.assertOk(ll)
        self.assertAlmostEqual(ll['latitude'], 52.4)
        self.assertAlmostEqual(ll['longitude'], -2.35)

        # Check an invalid coordinate
        ll = self.c.parse_latlong('52.4')
        self.assertNotOk(ll)

    def test_distance_sort(self):
        """Test sorting results by distance.

        """
        self.create_geo_database()

{
    'field_name': 'latlong',
        'type': 'geo',
        'store': True,
        'geo': {}
},


if __name__ == '__main__':
    main()
